package nix.hibernate;

import java.util.List;

import nix.domain.Customer;
import nix.utils.HibernateUtils;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;

public class DemoDetached {

	@Test
	public void fun1() {
		// 离线查询
		DetachedCriteria dc = DetachedCriteria.forClass(User.class);
		dc.add(Restrictions.idEq(3));

		Session session = HibernateUtils.getSession();
		Transaction tx = session.beginTransaction();
		// DetachedCriteria创建Criteria
		Criteria criteria = dc.getExecutableCriteria(session);
		List list = criteria.list();

		System.out.println(list);

		tx.commit();
		session.close();
	}
}
